<?php
/**
 * Copyright (c) 2016.  hangzhou BOYE .Co.Ltd. All rights reserved
 */

/**
 * Created by PhpStorm.
 * User: 1
 * Date: 2016-12-29
 * Time: 11:44
 */

namespace app\web\controller;



use app\pc\helper\PcFunctionHelper;
use app\src\product\logic\ProductimageLogic;
use app\src\shoppingCart\action\ShoppingCartQueryAction;
use app\web\controller\Base;
use app\src\product\logic\ProductLogic;
class Shop extends Base
{
    protected function _initialize()
    {
        parent::_initialize();
        $this->assignNav('商城');
    }

    public function index()
    {

        $this->redirect(url('shop/product_kind'));
        return $this->fetch();
    }
    protected function assignNav($nav = '首页'){
        $this->assign('nav', $nav);
    }


    public function product_list()
    {
        $map['onshelf']='1';
        $map['status']='1';
        $code=$this->_param('code');
        $map['product_code']=array('like',"%$code%");
        $order='itboye_product.create_time desc';
        $result=(new ProductLogic())->plist($map,$order);
        if(!$result['status']) $this->error('查询数据出错');
        if(strstr($code, '00S001')){
            $this->assignTitle('肤倍柔系列');
            $this->assign('title','肤倍柔系列');
            $this->assign('has','1');
        }elseif(strstr($code, '00S002')){
            $this->assignTitle('驱蚊系列');
            $this->assign('title','驱蚊系列');
            $this->assign('has','0');
        }elseif(strstr($code, '00S003')){
            $this->assignTitle('洗护系列');
            $this->assign('title','洗护系列');
            $this->assign('has','0');
        }elseif(strstr($code, '00S004')){
            $this->assignTitle('湿巾系列');
            $this->assign('title','湿巾系列');
            $this->assign('has','0');
        }elseif(strstr($code, '00S005')){
            $this->assignTitle('成人系列');
            $this->assign('title','成人系列');
            $this->assign('has','0');
        }elseif(strstr($code, '00S006')){
            $this->assignTitle('护粉');
            $this->assign('title','护粉');
            $this->assign('has','0');
        }elseif(strstr($code, '00S007')){
            $this->assignTitle('洗衣类');
            $this->assign('title','洗衣类');
            $this->assign('has','0');
        }elseif(strstr($code, '00S008')){
            $this->assignTitle('其他系列');
            $this->assign('title','其他系列');
            $this->assign('has','0');
        }
        if(empty($result['info'])){
            $this->assign('list', []);
            return $this->fetch();
        }
        $product=$result['info'];

        foreach($product as $k=>$v){
            $list[$k]['id']=$v['id'];
            $list[$k]['name']=$v['name'];
            $list[$k]['img_id']=$v['img_main']['img_id'];
            $list[$k]['specifications']=$v['specifications'];

        }
        $this->assign('list', $list);
        return $this->fetch();
    }




    public function product_detail()
    {

        $map['id']=$this->_param('id');
        $order='itboye_product.create_time desc';
        $result=(new ProductLogic())->detail($map,$order);
        $detail=$result['info'][0];
        //dump($detail);
        if(!empty($detail['img_follow'][0]['img_id'])) {
            $img = $detail['img_follow'][0]['img_id'];
            $this->assign('img',$img);
        }else{
            $this->assign('img',0);
        }
      //  dump($img);exit;


        return $this->fetch();
    }



    public function coding(){
        $this->assignTitle('正在开发中……');
        return $this->fetch();
    }


}